<?php

/**
 * Gets all support cases
 * @package ModuleAssistance
 * @version 1.0b
 * @return table
 */

session_start();

// Configuration file
include '../configuration.php';
// Functions
include '../inc/functions.php';

// Checking if user is logged in
if (!CheckSession()):
	exit();
endif;

// Include all objects
// TODO: Include only needed classes
foreach (glob($configuration['webroot'].'objects/*.php') as $class) { include_once $class; }

$supportcase = new SupportCase();
$supportcaseList = $supportcase->GetList(Array(Array('supportcaseId', '>', '0')), 'date', false); ?>

<table cellpadding="0" cellspacing="0" border="0" class="table-objects">
	<tr>
		<th class="check"></th>
		<th>#</th>
		<th>Date</th>
		<th>Priorité</th>
		<th>Contact</th>
	</tr>
	<?php foreach ($supportcaseList as $supportcase) {
		$contact = $supportcase->GetContact();
		$date = explode('-', substr($supportcase->date, 0, 10));
		$date = $date[2].'/'.$date[1].'/'.$date[0].' à '.substr($supportcase->date, 11, 5);
		
		$res  = '<tr>';
		$res .= '<td class="check"><input name="all" type="radio" value="'.$supportcase->supportcaseId.'" /></td>';
		$res .= '<td>'.$supportcase->supportcaseId.'</td>';
		$res .= '<td>'.$date.'</td>';
		$res .= '<td>'.$priority[$supportcase->priority].'</td>';
		$res .= '<td><a href="contacts.php?id='.$contact->contactId.'&operation=edit" target="_blank">'.$contact->lastname.' '.$contact->firstname.'</a></td>';
		$res .= '</tr>';
		echo $res;
	} ?>
</table>